package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtSupplierRating;
import com.ruoyi.business.service.IJtSupplierRatingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商评分Controller
 * 
 * @author Alan Zhang
 * @date 2025-05-22
 */
@Controller
@RequestMapping("/supplier/rating")
public class JtSupplierRatingController extends BaseController
{
    private String prefix = "supplier/rating";

    @Autowired
    private IJtSupplierRatingService jtSupplierRatingService;

    @RequiresPermissions("supplier:rating:view")
    @GetMapping()
    public String rating()
    {
        return prefix + "/rating";
    }

    /**
     * 查询供应商评分列表
     */
    @RequiresPermissions("supplier:rating:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtSupplierRating jtSupplierRating)
    {
        startPage();
        List<JtSupplierRating> list = jtSupplierRatingService.selectJtSupplierRatingList(jtSupplierRating);
        return getDataTable(list);
    }

    /**
     * 导出供应商评分列表
     */
    @RequiresPermissions("supplier:rating:export")
    @Log(title = "供应商评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtSupplierRating jtSupplierRating)
    {
        List<JtSupplierRating> list = jtSupplierRatingService.selectJtSupplierRatingList(jtSupplierRating);
        ExcelUtil<JtSupplierRating> util = new ExcelUtil<JtSupplierRating>(JtSupplierRating.class);
        return util.exportExcel(list, "供应商评分数据");
    }

    /**
     * 新增供应商评分
     */
    @RequiresPermissions("supplier:rating:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商评分
     */
    @RequiresPermissions("supplier:rating:add")
    @Log(title = "供应商评分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtSupplierRating jtSupplierRating)
    {
        return toAjax(jtSupplierRatingService.insertJtSupplierRating(jtSupplierRating));
    }

    /**
     * 修改供应商评分
     */
    @RequiresPermissions("supplier:rating:edit")
    @GetMapping("/edit/{ratingId}")
    public String edit(@PathVariable("ratingId") Long ratingId, ModelMap mmap)
    {
        JtSupplierRating jtSupplierRating = jtSupplierRatingService.selectJtSupplierRatingByRatingId(ratingId);
        mmap.put("jtSupplierRating", jtSupplierRating);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商评分
     */
    @RequiresPermissions("supplier:rating:edit")
    @Log(title = "供应商评分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtSupplierRating jtSupplierRating)
    {
        return toAjax(jtSupplierRatingService.updateJtSupplierRating(jtSupplierRating));
    }

    /**
     * 删除供应商评分
     */
    @RequiresPermissions("supplier:rating:remove")
    @Log(title = "供应商评分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtSupplierRatingService.deleteJtSupplierRatingByRatingIds(ids));
    }
}
